#include "foreground.hpp"

Vibe::Vibe(Process *pro):Observer(pro)
{
	/* Get a model data structure */
	vibe_model = libvibeModelNew();
	libvibeModelSetMatchingNumber(vibe_model, 1);
	libvibeModelSetUpdateFactor(vibe_model, 10);
}

Vibe::~Vibe()
{
	Log("Release Vibe");
	libvibeModelFree(vibe_model);
	mask.Release();
	
	_pro->Detach(this);
}
	 
void Vibe::Update(const Image &image)
{
	if(_pro->m_count == 1 && (_pro->AddFrameFlag))
	{
		/* Allocates the model and initialize it with the first image */
		mask = Image(image.width, image.height, 1);
		libvibeModelAllocInit_8u_C3R(vibe_model, image.data, image.width, image.height, image.widthStep);
	}
	else
	if(_pro->AddFrameFlag)
	{
		libvibeModelUpdate_8u_C3R(vibe_model, image.data, mask.data);
	}
}
